package com.itheima.test13;

/**
 * @Author:gy
 * @Date: 2025/09/01 16:48
 * @Description:
 */
public class Demo {
    public static void main(String[] args) {
        //创建两把锁
        Object o1 = new Object(); //筷子
        Object o2 = new Object(); //碗
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    synchronized (o1) {//筷子
                        synchronized (o2) {
                            System.out.println("张三吃饭");
                        }
                    }
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    synchronized (o2) {//筷子
                        synchronized (o1) {
                            System.out.println("李四吃饭");
                        }
                    }
                }
            }
        }).start();
    }
}
